package top.rainbowecho.notify.infrastructure.controller;

import com.google.common.collect.ImmutableMap;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import top.rainbowecho.common.util.ResultKey;
import top.rainbowecho.notify.domain.model.email.db.entity.MailTemplate;
import top.rainbowecho.notify.domain.model.email.db.repository.TemplateMapper;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author rainbow
 * @since 2020/4/30 16:10
 */
@RestController
public class NotifyController {
    private TemplateMapper templateMapper;

    @Resource
    public void setTemplateMapper(TemplateMapper templateMapper) {
        this.templateMapper = templateMapper;
    }

    @PostMapping("/template")
    public ResponseEntity<Map<String, Object>> addMailTemplate(MailTemplate template) {
        template.setCreateTime(LocalDateTime.now());
        this.templateMapper.insert(template);
        ImmutableMap<String, Object> result = ImmutableMap.of(ResultKey.DATA, template);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}
